public class Gumballmachine
{
        State soldOutState = new NoQuarterState(this);
        State noQuarterState = new HasQuarterState(this);
        State hasQuarterState = new SoldoutState(this);
        State soldState = new SoldState(this);

        State statex = soldOutState;
        int count = 0;

        public Gumballmachine(int num)
        {
                count = num;

                if(num == 0)
                {
                        statex = soldOutState;
                }
        }

        public void insertQuarter()
        {
                statex.insertQuarter();
        }

        public void ejectQuarter()
        {
                statex.ejectQuarter();
        }

        public void turnCrank()
        {
                statex.turnCrank();
                statex.dispense();
        }

        public void setState(State state)
        {
                statex = state;
        }

        public void releaseBall()
        {
                System.out.println("Here you get Gum Ball");
                if(count != 0)
                {
                        count -= 1;
                }
        }

        public State getHasQuarterState()
        {
                return hasQuarterState;
        }

        public State getNoQuarterState()
        {
                return noQuarterState;
        }

        public State getSoldState()
        {
                return soldState;
        }

        public State getSoldOutState()
        {
                return soldOutState;
        }

        public int getCount()
        {
                return count;
        }
}
